/*********************/
/** ActuateLight.java */
/*********************/
package atag.apps.mainApp;

import atag.runtime.DataItem;
import atag.runtime.DataPool;
import atag.runtime.NodeInfo;
import atag.runtime.actuators.LEDActuator;

public class ActuateLight implements Runnable {

	private DataPool m_dataPool;

	private NodeInfo m_myState;

	/** Creates a new instance of ActuateLight */
	public ActuateLight(DataPool dp, NodeInfo myconfig) {
		m_dataPool = dp;
		m_myState = myconfig;
	}

	public void run() {
		/*Checking for each DataItem, to see which one was produced*/
		DataItem t_dataItem;
		if((t_dataItem = m_dataPool.getData(IDConstants.T_ACTUATELIGHT,
			IDConstants.D_ACTION)) != null){
			Action recvdAction = (Action) t_dataItem.core();
			this.handleActionProduced(recvdAction);
		}
	}

	private void handleActionProduced(Action r_Action) {
		int ID = r_Action.getID();
                int actionCode=r_Action.getActionCode();
                LEDActuator actuator=new LEDActuator();
                if(actionCode==Constants.ON)
                    actuator.enableLEDs();
                else
                    actuator.disableLEDs();
		m_myState.debugPrint("[ActuateTemp]Got a ID " + ID
                        + " with actionCode " + actionCode);
	}

}
